package com.hongye.third.controller;


import com.hongye.third.utils.GaoDeMapUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @progam:medical-care
 * @author:GJS
 * @Time:2022/4/15 19:58
 */
@RestController
@RequestMapping("/point")
public class GaoDeMapController {


    @Resource
    private GaoDeMapUtil gaoDeMapUtil;

    public static final Logger log = LoggerFactory.getLogger(GaoDeMapController.class);


    @ApiOperation(value = "根据经纬度获取地址")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "longitude", value = "经度"),
            @ApiImplicitParam(name = "latitude", value = "纬度")
    })
    @PostMapping("/getAddress")
    public String getAddress(@RequestParam("longitude") String longitude, @RequestParam("latitude") String latitude) {
        try {
            return gaoDeMapUtil.getAddress(longitude, latitude);
        } catch (Exception e) {
            return e.toString();
        }

    }

    @ApiOperation(value = "根据地址获取经纬度")
    @ApiImplicitParam(name = "address", value = "地理位置")
    @PostMapping("/getLonLat")
    public String getLonLat(String address) {
        return gaoDeMapUtil.getLonLat(address);
    }

    @ApiOperation(value = "根据两个定位点的经纬度算出两点间的距离(单位：米)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startLonLat", value = "起始经纬度"),
            @ApiImplicitParam(name = "endLonLat", value = "结束经纬度")
    })
    @PostMapping("/getDistance")
    public String getDistance(String startLonLat, String endLonLat) {
        return gaoDeMapUtil.getDistance(startLonLat, endLonLat);
    }

}
